package cn.cycleif.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * &#064;Date: 24/06/01-13:36
 * &#064;Description: 文档配置
 */
@Configuration
public class Knife4jCfg {

  @Bean
  public GroupedOpenApi publicApi() {
    return GroupedOpenApi.builder()
                         .group("public")
                         .pathsToMatch("/api/**")
                         .build();
  }

  @Bean
  public GroupedOpenApi adminApi() {
    return GroupedOpenApi.builder()
                         .group("admin")
                         .pathsToMatch("/sys/**")
                         // .addOpenApiMethodFilter(method -> method.isAnnotationPresent(Admin.class))
                         .build();
  }

  @Bean
  public OpenAPI downpourOpenAPI() {
    return new OpenAPI()
        .info(info())
        .externalDocs(externalDocumentation());
  }

  private License license() {
    return new License()
        .name("MIT")
        .url("https://opensource.org/licenses/MIT");
  }

  private Info info() {
    return new Info()
        .title("Downpour")
        .description("downpour api docs")
        .version("v1.0.0")
        .license(license());
  }

  private ExternalDocumentation externalDocumentation() {
    return new ExternalDocumentation()
        .description("这是一个额外的描述。")
        .url("https://xx");
  }

}
